package com._520it.crm.web.controller;

import com._520it.crm.domain.AccountInfo;
import com._520it.crm.page.PageResult;
import com._520it.crm.query.AccountInfoQueryObject;
import com._520it.crm.service.IAccountInfoService;
import com._520it.crm.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by 呆 on 2017/10/3.
 */
@Controller
@RequestMapping("/accountInfo")
public class AccountInfoController {
    @Autowired
    private IAccountInfoService accountInfoService;
    @RequestMapping("")
    public String index(){
        return "accountInfo";
    }

    @RequestMapping("/list")
    @ResponseBody
    public PageResult list(AccountInfoQueryObject qo){
         return accountInfoService.query(qo);
    }

    /**
     * 保存提交保单时填写的银行账户信息
     * @param accountInfo 银行账户对象信息 前台传过来的
     * @param applyClient 前台传过来的 保单申请人的身份证号码
     * @return
     */
    @RequestMapping("saveAccountInfo")
    @ResponseBody
    public AjaxResult saveAccountInfo(AccountInfo accountInfo,String applyClient){
        AjaxResult result = null;
        try {
            accountInfoService.saveAccountInfo(accountInfo,applyClient);
            result = new AjaxResult("保存成功");
        } catch (Exception e) {
            e.printStackTrace();
            result = new AjaxResult(false,"保存失败");
        }
        return result;
    }
    /**
     * 修改保单时 提交修改的银行账户信息
     * @param accountInfo 银行账户对象信息 前台传过来的
     * @return
     */
    @RequestMapping("updateAccountInfo")
    @ResponseBody
    public AjaxResult updateAccountInfo(AccountInfo accountInfo ){
        AjaxResult result = null;
        try {
            accountInfoService.updateByPrimaryKey(accountInfo);
            result = new AjaxResult("保存成功");
        } catch (Exception e) {
            e.printStackTrace();
            result = new AjaxResult(false,"保存失败");
        }
        return result;
    }
}
